<!--
描述：题库重复情况组件
开发人：hqj
开发日期：2018年11月15日
-->
<template lang="pug">
    div.kalix-article(v-if="pageShow")
        div.frame-header
            div.frame-header--cnt
                el-form(ref="searchForm" v-bind:model="formModel" v-bind:inline="true" v-on:submit.native.prevent="")
                    el-form-item(label="题型" prop="questionType" v-bind:rules="rules.questionType" label-width="65px")
                        kalix-dict-select(v-model="formModel.questionType" appName="enrolment" dictType="题型" v-on:dictSelected="dictSelected")
                    el-form-item(v-if="formModel.questionType === '5'" label="题型子类" prop="subType" label-width="75px")
                        kalix-dict-select(v-model="formModel.subType" appName="enrolment" dictType="主观题类型")
                    el-form-item(v-if="formModel.questionType === '6'" label="题型子类" prop="subType" label-width="75px")
                        kalix-dict-select(v-model="formModel.subType" appName="enrolment" dictType="面试题类型")
                    el-form-item(v-if="formModel.questionType === '1' || formModel.questionType === '2' || formModel.questionType === '3'"
                    label="试题类别" prop="type" label-width="75px")
                        kalix-dict-select(v-model="formModel.type" appName="enrolment" dictType="类别")
                    el-form-item(label="去重相似度" prop="similarity" v-bind:rules="rules.similarity" label-width="95px")
                        el-input(v-model="formModel.similarity")
                    el-form-item
                        el-button(type="success" v-on:click="onQueryClick")
                            i.iconfont.icon-query
                            | 查询
                        el-button(type="primary" v-on:click="onResetClick")
                            i.iconfont.icon-reset
                            | 重置
        div.frame-article
            div.frame-item
                keep-alive
                    kalix-table(bizKey="allRepeatedQuery" title='题库重复试题列表' v-bind:targetURL="allRepeatedInfoURL"
                    v-bind:toolbarBtnList="toolbarBtnList" v-bind:isFixedColumn="isFixedColumn" ref="kalixTable1")
                        template(slot="tableColumnSlot")
                            el-table-column(prop="subTypeName" label="题型子类" align="center" width="150px")
                            el-table-column(prop="typeName" label="试题类别" align="center" width="180px")
                            el-table-column(prop="questionId" label="ID" align="center" width="150px")
                            el-table-column(prop="stem" label="题干" align="center" width="700px")
                                template(slot-scope="scope")
                                    el-popover(trigger="hover" placement="top" width="700")
                                        | {{scope.row.stem}}
                                        div(slot="reference")
                                            template(v-if="scope.row.stem && scope.row.stem.length > 50")
                                                | {{scope.row.stem.substr(0, 50)}}...
                                            template(v-else)
                                                | {{scope.row.stem}}
                            el-table-column(prop="createBy" label="创建者" align="center" width="150px")
                            el-table-column(prop="creationDate" label="创建时间" align="center" width="220px")
                                template(slot-scope="scope")
                                    i(class="el-icon-time")
                                    span {{scope.row.creationDate}}
            div.frame-article--split
            div.frame-item
                keep-alive
                    kalix-table(bizKey="questionRepeated" title='试题重复次数列表' v-bind:targetURL="questionRepeatedURL"
                    v-bind:toolbarBtnList="toolbarBtnList" v-bind:isFixedColumn="isFixedColumn" ref="kalixTable2")
                        template(slot="tableColumnSlot")
                            el-table-column(prop="subTypeName" label="题型子类" align="center" width="150px")
                            el-table-column(prop="firstQuestionId" label="排重试题id" align="center" width="150px")
                            el-table-column(prop="firstStem" label="排重试题题干" align="center" width="430px")
                                template(slot-scope="scope")
                                    el-popover(trigger="hover" placement="top" width="430")
                                        | {{scope.row.firstStem}}
                                        div(slot="reference")
                                            template(v-if="scope.row.firstStem && scope.row.firstStem.length > 30")
                                                | {{scope.row.firstStem.substr(0, 30)}}...
                                            template(v-else)
                                                | {{scope.row.firstStem}}
                            el-table-column(prop="secondQuestionId" label="重复试题id" align="center" width="150px")
                            el-table-column(prop="secondStem" label="重复试题题干" align="center" width="430px")
                                template(slot-scope="scope")
                                    el-popover(trigger="hover" placement="top" width="430")
                                        | {{scope.row.secondStem}}
                                        div(slot="reference")
                                            template(v-if="scope.row.secondStem && scope.row.secondStem.length > 30")
                                                | {{scope.row.secondStem.substr(0, 30)}}...
                                            template(v-else)
                                                | {{scope.row.secondStem}}
                            el-table-column(prop="similarityDesc" label="相似度说明" align="center" width="240px")
    div(v-else) 题库功能已关闭，如需使用请联系管理员！
</template>

<script type="text/ecmascript-6">
    import FormModel from './model'
    import {AllRepeatedInfoURL, QuestionRepeatedURL} from '../../config.toml'
    /*import {availableQuestion} from '../../common.js'*/

    export default {
        name: 'kalix-enrolment-allrepeatedquery',
        data() {
            var validateSimilarity = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('请输入去重相似度'));
                }
                if (/^(0.\d+|0|1)$/.test(value)) {
                    callback();
                } else {
                    callback(new Error('请输入0～1之间的数字值'));
                }
            }
            return {
                pageShow: false,
                formModel: Object.assign({}, FormModel),
                rules: {
                    questionType: [{required: true, message: '请选择题型', trigger: 'change'}],
                    similarity: [{required: true, validator: validateSimilarity, trigger: 'blur'}]
                },
                labelWidth: '120px',
                toolbarBtnList: [
                    {id: 'add', isShow: false}
                ],
                allRepeatedInfoURL: AllRepeatedInfoURL,
                questionRepeatedURL: QuestionRepeatedURL,
                isFixedColumn: true
            }
        },
        components: {},
        created() {
            /*availableQuestion(this.axios, this.$KalixMessage, flag => {
             this.pageShow = flag
             })*/
            this.pageShow = true
        },
        mounted() {
        },
        computed: {},
        methods: {
            dictSelected(dict) {
                this.formModel.subType = ''
                this.formModel.type = ''
            },
            // 查询
            onQueryClick() {
                this.$refs.searchForm.validate((valid) => {
                    if (valid) {
                        this.clearTableData(0)
                        let queryCondition = {}
                        queryCondition['questionType'] = this.formModel.questionType
                        if (this.formModel.subType && this.formModel.subType.length) {
                            queryCondition['subType'] = this.formModel.subType
                        }
                        if (this.formModel.type && this.formModel.type.length) {
                            queryCondition['type'] = this.formModel.type
                        }
                        if (this.formModel.similarity && this.formModel.similarity.length) {
                            queryCondition['similarity'] = this.formModel.similarity
                        }
                        let jsonStr = JSON.stringify(queryCondition)
                        let searchObjAll = {jsonStr: jsonStr}
                        this.$KalixEventBus.$emit(this.$KalixEventConfig.ON_SEARCH_BUTTON_CLICK, searchObjAll)
                    } else {
                        this.$KalixMessage.error('请检查输入项！')
                        return
                    }
                })
            },
            // 重置搜索框
            onResetClick() {
                this.$refs.searchForm.resetFields()
                this.clearTableData(0)
            },
            // 清除列表数据0全部
            clearTableData(num) {
                switch (num) {
                    // 清除所有列表数据
                    case 0 :
                        this.$refs.kalixTable1.clearData()
                        this.$refs.kalixTable2.clearData()
                        break
                    default :
                        this.$refs.kalixTable1.clearData()
                        this.$refs.kalixTable2.clearData()
                        break
                }
            }
        }
    }
</script>

<style scoped lang="stylus">
    .frame-header
        background-color rgb(255, 255, 255)
        padding-top 7px
        margin-bottom 7px

    .frame-article
        flex 1
        display flex
        flex-direction column
        .frame-article--split
            height 7px
        .frame-item
            flex 1
</style>
